home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / listings / v_03_02 / 3n02068a < prev    next >
Text File  |  1991-12-17  |  977b  |  52 lines

  1. const
  2.     BITS_PER_SET = 256;
  3.     BYTES_PER_SET = 32;
  4. type
  5.     bitset = array [0 .. BYTES_PER_SET] of byte;
  6.  
  7. procedure empty(var s : bitset);
  8.     ...
  9.  
  10. function member(e : integer; var s : bitset) : boolean;
  11.     ...
  12.  
  13. procedure display(var s : bitset);
  14.     ...
  15.  
  16. {*
  17.  * Expand set s1 into (256-element) bitset s2. length is
  18.  * the length in bytes of s1.  offset is the byte offset
  19.  * in s2 that corresponds to the first byte of s1.
  20.  *}
  21. procedure expand
  22.     (var s1; var s2 : bitset; length, offset : byte);
  23.     var
  24.         i, j : integer;
  25.         p : ^bitset;
  26.     begin
  27.     p := addr(s1);
  28.     empty(s2);
  29.     i := offset;
  30.     for j := 0 to length - 1 do
  31.         begin
  32.         s2[i] := p^[j];
  33.         i := i + 1;
  34.         end;
  35.     end;
  36.  
  37. const
  38.     LB = 21;
  39.     HB = 50;
  40. var
  41.     s : set of LB .. HB;
  42.     b : bitset;
  43.     i : integer;
  44. begin
  45. s := [22, 32, 42];
  46. expand(s, b, HB div 8 - LB div 8 + 1, LB div 8);
  47. write('b = '); display(b);
  48. for i := 0 to BITS_PER_SET do
  49.     if member(i, b) then
  50.         writeln(i:2, ' is a member of b');
  51. end.
  52.